#include "stdafx.h"
#include "ComMethodMatcher.h"
#include "ComDispatch.h"

CComMethodMatcherBase::CComMethodMatcherBase(const std::wstring& _methodName)
	:methodName(_methodName)
{
}

bool CComMethodMatcherBase::Matches(CJoinPoint& joinPoint)
{
	CComDispatch dispatch(joinPoint);
	HRESULT hr = S_OK;
	CComPtr<ITypeInfo> pTypeInfo;
	hr = dispatch.GetTypeInfo(0,0,&pTypeInfo);
	if ( pTypeInfo == NULL )
	{
		return false;
	}
	FUNCDESC* pFuncDesc = NULL;
	hr = pTypeInfo->GetFuncDesc(joinPoint.GetFuncIndex(),&pFuncDesc);
	if ( pFuncDesc == NULL )
	{
		return false;
	}
	MEMBERID funcId = pFuncDesc->memid;
	pTypeInfo->ReleaseFuncDesc(pFuncDesc);
	CComBSTR funcName;
	hr = pTypeInfo->GetDocumentation(funcId,&funcName,NULL,NULL,NULL);
	if ( FAILED(hr) )
	{
		return false;
	}
	LPCTSTR currentFunc = (LPCTSTR)((BSTR)funcName);
	LPCTSTR func = (LPCTSTR)methodName.c_str();
	return (_tcscmp(currentFunc,func)==0);
}

